//
//  SAShopSaleFooterView.m
//  saasRetail
//
//  Created by mac on 2023/8/22.
//

#import "SAShopSaleFooterView.h"
#import "SASalesOrderViewListModel.h"

@interface SAShopSaleFooterView ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UISwitch *mySwitch;

@end

@implementation SAShopSaleFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

-(void)setDataModel:(SASalesOrderViewListModel *)dataModel {
    _dataModel = dataModel;
    self.titleLab.text = dataModel.activityName;
    self.nameLab.text = dataModel.activityTitle;
    self.mySwitch.on = dataModel.isOpenActivity;
}

#pragma mark - event
- (void)switchAction:(UISwitch *) s1 {
    if (s1.on == YES) {
        self.dataModel.isOpenActivity = YES;
        !self.onBlock ?: self.onBlock(@"1");
    }else{
        self.dataModel.isOpenActivity = NO;
        !self.onBlock ?: self.onBlock(@"0");
    }
}

-(void)initUI {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.nameLab];
    [self.contentView addSubview:self.mySwitch];

}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(50, 0, 150, 35)];
        _titleLab.textColor = kPinkColor;
        _titleLab.font = kFont(15);
        _titleLab.text = @"";
    }
    return _titleLab;
}

-(UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] initWithFrame:SARectMake(205, 0, 100, 35)];
        _nameLab.textColor = kBlackColor;
        _nameLab.font = kFont(15);
        _nameLab.text = @"";
        _nameLab.textAlignment = NSTextAlignmentRight;
    }
    return _nameLab;
}

-(UISwitch *)mySwitch {
    if (!_mySwitch) {
        _mySwitch = [[UISwitch alloc] initWithFrame:SARectMake(0, 0, 0, 0)];
        _mySwitch.y = (kScaleNum(35) - _mySwitch.height)/2;
        _mySwitch.x = kScreenWidth - _mySwitch.width - kScaleNum(15);
        [_mySwitch setOnTintColor:kGreenColor];
        [_mySwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    }
    return _mySwitch;
}


@end
